package view.components
{
	import flash.display.Bitmap;
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.TimerEvent;
	
	import global.Resource;
	
	import utils.EnterFrameTimer;
	import view.components.TempBitmap;

	public class SimpleLoading extends Sprite
	{
		private var face:DisplayObject;
		private var timer:EnterFrameTimer;
		
		public function SimpleLoading()
		{
			initFace();
			initTimer();
		}
		
		private function initTimer():void
		{
			timer = new EnterFrameTimer(40);
			timer.addEventListener(TimerEvent.TIMER,onTimer);
		}
		
		private function onTimer(event:TimerEvent):void
		{
			this.rotation+= 30;
		}
		
		private function initFace():void
		{
			face = Resource.getImg("panel_loading",true);
			//face.x = (this.width - face.width) * .5
			//face.y = (this.height - face.height) * .5 + 2;
			
			face.x = -20;
			face.y = -20;
			addChild(face);
			
			if (face is TempBitmap)
			{
				face.addEventListener(Event.COMPLETE,onFaceComplete);
			}
		}
		
		private function onFaceComplete(event:Event):void
		{
			event.target.removeEventListener(Event.COMPLETE,onFaceComplete);
			face.x = -20;
			face.y = -20;
			
			(face as Bitmap).smoothing = true;
			
			
		}
		
		public function start():void
		{
			timer.start();
		}
		
		public function stop():void
		{
		
			timer.reset();
		}
		
	}
}